package br.com.vti.sisp_sicrim.model.entity;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import br.com.crud4j.core.model.Model;
import br.com.vti.sisp_sicrim.model.entity.enums.Status;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_endereco", catalog = "desenvolvimento", schema = "e_sisp_sicrim")
@SequenceGenerator(name = "seq_endereco", sequenceName = "e_sisp_sicrim.seq_endereco", initialValue = 1, allocationSize = 1)
public class Endereco implements Model<Integer> {
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_endereco")
	@Basic(optional = false)
	private Integer id;
	
	@Basic(optional = false)
	@NotNull
	@ManyToOne
    @JoinColumn(name = "tp_logradouro", referencedColumnName = "id")
//	@Column(name = "tp_logradouro")
	private TipoLogradouro tpLogradouro;
	
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 200)
	@Column(name = "nm_logradouro")
	private String nmLogradouro;
	
	private Integer numero;
	
	@Size(max = 100)
	private String complemento;
	
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 100)
	private String bairro;
	
	private Integer cep;
	
	@Basic(optional = false)
	@NotNull
	@ManyToOne
    @JoinColumn(name = "municipio", referencedColumnName = "id")
	private Municipio municipio;
	
    @Column(columnDefinition="bpchar(1) default 'A'")
    private Status status;

	public Endereco() {
	}

	public Endereco(Integer id) {
		this.id = id;
	}

	public Endereco(Integer id, TipoLogradouro tpLogradouro, String nmLogradouro,
			String bairro, Municipio municipio) {
		this.id = id;
		this.tpLogradouro = tpLogradouro;
		this.nmLogradouro = nmLogradouro;
		this.bairro = bairro;
		this.municipio = municipio;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNmLogradouro() {
		return nmLogradouro;
	}

	public void setNmLogradouro(String nmLogradouro) {
		this.nmLogradouro = nmLogradouro;
	}

	public Integer getNumero() {
		return numero;
	}

	public void setNumero(Integer numero) {
		this.numero = numero;
	}

	public String getComplemento() {
		return complemento;
	}

	public void setComplemento(String complemento) {
		this.complemento = complemento;
	}

	public String getBairro() {
		return bairro;
	}

	public void setBairro(String bairro) {
		this.bairro = bairro;
	}

	public Integer getCep() {
		return cep;
	}

	public void setCep(Integer cep) {
		this.cep = cep;
	}

	public TipoLogradouro getTpLogradouro() {
		return tpLogradouro;
	}

	public void setTpLogradouro(TipoLogradouro tpLogradouro) {
		this.tpLogradouro = tpLogradouro;
	}

	public Municipio getMunicipio() {
		return municipio;
	}

	public void setMunicipio(Municipio municipio) {
		this.municipio = municipio;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// not set
		if (!(object instanceof Endereco)) {
			return false;
		}
		Endereco other = (Endereco) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "br.com.vti.sisp_sicrim.model.entity.Endereco[ id=" + id + " ]";
	}

}
